<!doctype html>
<html  class="x-admin-sm">
<head>
	<meta charset="UTF-8">
	<title>后台登录</title>
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/login.css">
	  <link rel="stylesheet" href="./css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="./lib/layui/layui.js" charset="utf-8"></script>
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body class="login-bg" style="background: url(images/bg.jpg); background-size: 100% 100%; background-attachment: fixed">>
    
    <div class="login layui-anim layui-anim-up">
        <div class="message" style="text-align:center ;background:transparent;font-size:40px;font-family: STCAIYUN"; > 产品后台管理</div>

        
        <form method="post" class="layui-form">
            <input name="username" id="usernameId" placeholder="用户名"  type="text" lay-verify="required" class="layui-input" >
            <hr class="hr15" style="background-color:transparent;">
            <input name="password" id="passwordId" lay-verify="required" placeholder="密码"  type="password" class="layui-input">
            <hr class="hr15" style="background-color:transparent;">
            <input name="username" id="code" placeholder="验证码"  type="text" lay-verify="required" class="layui-input" >
             <hr class="hr15" style="background-color:transparent;">
             <img οnclick="javascript:getvCode()" id="verifyimg" style="margin-left: 20px;"/>
             <hr class="hr15" style="background-color:transparent;">
            <button type="button" id="btn"  class="layui-btn layui-btn-fluid layui-btn-radius">登录</button>
             
            <hr class="hr20" style="background-color:transparent;">
            
        </form>
    </div>

<script type="text/javascript">

getvCode();

/**
 * 获取验证码
 * 将验证码写到login.html页面的id = verifyimg 的地方
 */
function getvCode() {
    document.getElementById("verifyimg").src = timestamp("http://localhost:8081/verifyCode");
   	
    
}

//为url添加时间戳
 function timestamp(url) {
    var getTimestamp = new Date().getTime();
    if (url.indexOf("?") > -1) {
        url = url + "&timestamp=" + getTimestamp
    } else {
        url = url + "?timestamp=" + getTimestamp
    }
    return url;
};
    $(function(){
    	$("#btn").click(doLogin);
    })
    
   function doLogin(){
    	var url1="/verifyCode/checkVerify";
       	var params1= {code:$("#code").val()}
    	 var params={
    			 username:$("#usernameId").val(),
    			 password:$("#passwordId").val(),
    			
    		  }
    		  var url="admin/doLogin";
    		  console.log("params",params);
    		  $.post(url1,params1,verification)
			    function  verification(result){
			    if(result==true){
				    		  $.post(url,params,function(result){
				    			 
				    			  if(result.state==1){
				    				//跳转到indexUI对应的页面
				    				location.href="doIndex?t="+Math.random();
				    			  }else{
				    				alert("请输入正确的账号和密码")
				    			  }
				    			  return false;//防止刷新时重复提交
				    		  });
			    }else if(result==false){
			    	alert("验证码输入错误")
			    }
    		  }
    } 
</script>

</body>
</html>